<template>
	<view class="cart" v-if="cart.length!==0">
		<my-address></my-address>
		<view class="cart-title">
			<uni-icons type="shop" size="18"></uni-icons>
			<text class="cart-title-text">购物车</text>
		</view>
		<uni-swipe-action>
			<block v-for="(goods,i) in cart" :key="i">
				<uni-swipe-action-item :right-options="options" @click='swiperActionClickHandler(goods)'>
					<my-goods :v='goods' :show-radio="true" @radio-change='radioChangeHandler'
						@num-change='numberChangeHandler'></my-goods>
				</uni-swipe-action-item>
			</block>
		</uni-swipe-action>
		<my-settle></my-settle>
	</view>
	<view class="empty-box" v-else>
		<image class="empty-pic" src="../../static/empty.png" mode="widthFix"></image>
		<text>空空如也~</text>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		mixins: [badgeMix],
		data() {
			return {
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#c00000',
						padding: '20rpx 0'
					}
				}]
			};
		},
		computed: {
			...mapState({
				cart: state => state.m_cart.cart
			}),
		},
		methods: {
			...mapMutations('m_cart', ['updateGoodsState', 'updateGoodsNumber', 'removeGoodsById']),
			radioChangeHandler(e) {
				// console.log(e)
				// e.goods_state = !e.goods_state
				this.updateGoodsState(e)
			},
			numberChangeHandler(e) {
				// console.log(e)
				this.updateGoodsNumber(e)
			},
			//右滑删除
			swiperActionClickHandler(goods) {
				// console.log(goods)
				this.removeGoodsById(goods.goods_id)
			}
		}
	}
</script>

<style lang="scss">
	.cart {
		padding-bottom: 100rpx;
	}

	.cart-title {
		height: 80rpx;
		display: flex;
		align-items: center;
		border-bottom: 1px solid #efefef;
		font-size: 28rpx;
		padding-left: 10rpx;

		.cart-title-text {
			margin-left: 20rpx;
		}
	}
	.empty-box{
		width: 100%;
		height: 100vh;
		background-color: #fff;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		font-size: 24rpx;
		color: gray;
		.empty-pic{
			width: 300rpx;
		}
	}
</style>
